package com.hardydou.data.controller;

import com.github.pagehelper.PageInfo;
import com.hardydou.common.controller.BaseController;
import com.hardydou.common.result.Result;
import com.hardydou.common.result.ResultHelper;
import com.hardydou.data.model.YdIcon;
import com.hardydou.data.service.IYdIconServce;
import com.hardydou.framework.log.anno.LogMetaInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.hardydou.data.controller.FigmaController.REQ_PREFIX;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2021/2/2
 * @Copyright ：Hardydou.com
 */
@Controller
@LogMetaInfo(module = "YdIcon")
@RequestMapping(REQ_PREFIX)
public class FigmaController extends BaseController {
    final static String REQ_PREFIX = "/figma";
    @Autowired
    IYdIconServce iconServce;

    @Override
    public String getModel() {
        return "data";
    }

    @Override
    public String getSubModel() {
        return "yd";
    }

    @GetMapping("")
    public String figma() {
        return page("figma");
    }

    @ApiOperation(value = "图标搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", defaultValue = "10", required = true)
    })
    @GetMapping("/icons")
    @ResponseBody
    public Result<?> icons(int pageNum, int pageSize, @RequestParam Map params) {
        List<YdIcon> icons = iconServce.list(params);
        PageInfo<YdIcon> pageInfo = new PageInfo<>(icons);
        return ResultHelper.ok(pageInfo);
    }

}
